package com.thon.entity.project;

// Generated 2013-9-23 19:12:56 by Hibernate Tools 3.4.0.CR1

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.thon.commons.config.Global;
import com.thon.commons.utils.ImageUrl;
import com.thon.commons.web.Servlets;
import com.thon.entity.user.Institution;
import com.thon.entity.util.IdEntity;

/**
 * project generated by hbm2java
 */
@Entity
@Table(name = "projects") 
@JsonIgnoreProperties(ignoreUnknown = true)
public class Project extends IdEntity {

	private static final long serialVersionUID = -7549842588315162385L;
	//private Institution institution;
	private Region cityRegion;
	private Region provinceRegion;
	private Region districtRegion;
	private ProjectCategory projectCategory;
	private ProjectCategory projectBenefit;
	private ProjectCategory projectOpen;
	private String userQQ;
	private String userPhone;
	private Byte userGender;
	private String userRealName;
	private String name;
	private String activityContent;
	private String activityBackground;
	private String requirementAnalysis;
	private String activityObject;
	private String description;
	private String address;
	private Date createdDate;
	private Integer photoId;
	private Integer validDays;
	private Integer fundTarget;
	private Integer fundCurrent;
	private String tags;
	private Integer status;
	private Integer shareCount;
	private Integer supportCount;
	private Integer unSupportCount;
	private Integer commentCount;
	private Integer attentionCount;
	private Integer recommendCount;
	private Integer viewCount;
	private Integer isAttention;
	private Integer isRecommended;
	private Integer remainingDay;
	private Date fundraisingDate;
	private Institution institution;
	private Integer productAmount;
	private Integer contect;
	
	//项目的状态，1-预审，5-进行中的项目，6-关闭的项目
	public static final Integer PROJECT_STATUS_PER = 1;
	public static final Integer PROJECT_STATUS_ING = 5;
	public static final Integer PROJECT_STATUS_CLOSE = 6;

	
	public Integer getContect() {
		return contect;
	}

	public void setContect(Integer contect) {
		this.contect = contect;
	}

	
	public Integer getProductAmount() {
		return this.productAmount;
	}

	public void setProductAmount(Integer productAmount) {
		this.productAmount = productAmount;
	}

	public Project(Date createdDate) {
		this.createdDate = createdDate;
	}
	
	public Project() {
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "city_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public Region getCityRegion() {
		return this.cityRegion;
	}

	public void setCityRegion(Region cityRegion) {
		this.cityRegion = cityRegion;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "institute_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public Institution getInstitution() {
		return this.institution;
	}

	public void setInstitution(Institution institution) {
		this.institution = institution;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "province_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public Region getProvinceRegion() {
		return this.provinceRegion;
	}

	public void setProvinceRegion(Region provinceRegion) {
		this.provinceRegion = provinceRegion;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "district_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public Region getDistrictRegion() {
		return this.districtRegion;
	}

	public void setDistrictRegion(Region districtRegion) {
		this.districtRegion = districtRegion;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "category_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public ProjectCategory getProjectCategory() {
		return this.projectCategory;
	}

	public void setProjectCategory(ProjectCategory projectCategory) {
		this.projectCategory = projectCategory;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "benefit_id", nullable = false)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public ProjectCategory getProjectBenefit() {
		return projectBenefit;
	}

	public void setProjectBenefit(ProjectCategory projectBenefit) {
		this.projectBenefit = projectBenefit;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "open_id", nullable = true)
	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
	public ProjectCategory getProjectOpen() {
		return projectOpen;
	}

	public void setProjectOpen(ProjectCategory projectOpen) {
		this.projectOpen = projectOpen;
	}

	@Column(name = "user_qq")
	public String getUserQQ() {
		return this.userQQ;
	}

	public void setUserQQ(String userQQ) {
		this.userQQ = userQQ;
	}

	public String getUserPhone() {
		return this.userPhone;
	}

	public void setUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}

	public Byte getUserGender() {
		return this.userGender;
	}

	public void setUserGender(Byte userGender) {
		this.userGender = userGender;
	}

	public String getUserRealName() {
		return this.userRealName;
	}

	public void setUserRealName(String userRealName) {
		this.userRealName = userRealName;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "content")
	public String getActivityContent() {
		return this.activityContent;
	}

	public void setActivityContent(String activityContent) {
		this.activityContent = activityContent;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getActivityBackground() {

		if(!StringUtils.isBlank(activityBackground)){
			activityBackground = StringEscapeUtils.unescapeHtml4(activityBackground);
			activityBackground = activityBackground.replaceAll("src=\"../common/attachment/download/", "src=\""+Global.getConfig("img.url"));
		}
		return activityBackground;
	}

	public void setActivityBackground(String activityBackground) {
		this.activityBackground = activityBackground;
	}

	public String getRequirementAnalysis() {
		return requirementAnalysis;
	}

	public void setRequirementAnalysis(String requirementAnalysis) {
		this.requirementAnalysis = requirementAnalysis;
	}

	public String getActivityObject() {
		return activityObject;
	}

	public void setActivityObject(String activityObject) {
		this.activityObject = activityObject;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Integer getPhotoId() {
		return this.photoId;
	}

	public void setPhotoId(Integer photoId) {
		this.photoId = photoId;
	}

	@Transient
	public String getPhotoUrl() {
		return ImageUrl.format(this.photoId);
	}

	public Integer getValidDays() {
		return this.validDays;
	}

	public void setValidDays(Integer validDays) {
		this.validDays = validDays;
	}

	public Integer getFundTarget() {
		return this.fundTarget;
	}

	public void setFundTarget(Integer fundTarget) {
		this.fundTarget = fundTarget;
	}

	public String getTags() {
		return this.tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public Integer getStatus() {
		return this.status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}
	
	public Integer getSupportCount() {
		return this.supportCount;
	}
	
	@Transient
	public Integer getUnSupportCount() {
		return unSupportCount;
	}

	public void setUnSupportCount(Integer unSupportCount) {
		this.unSupportCount = unSupportCount;
	}

	public void setSupportCount(Integer supportCount) {
		this.supportCount = supportCount;
	}

	public Integer getCommentCount() {
		return this.commentCount;
	}

	public void setCommentCount(Integer commentCount) {
		this.commentCount = commentCount;
	}

	public Integer getAttentionCount() {
		return this.attentionCount;
	}

	public void setAttentionCount(Integer attentionCount) {
		this.attentionCount = attentionCount;
	}

	public Integer getFundCurrent() {
		return fundCurrent;
	}

	public void setFundCurrent(Integer fundCurrent) {
		this.fundCurrent = fundCurrent;
	}

	public Integer getShareCount() {
		return shareCount;
	}

	public void setShareCount(Integer shareCount) {
		this.shareCount = shareCount;
	}

	public Integer getRecommendCount() {
		return recommendCount;
	}

	public void setRecommendCount(Integer recommendCount) {
		this.recommendCount = recommendCount;
	}

	public Integer getViewCount() {
		return viewCount;
	}

	public void setViewCount(Integer viewCount) {
		this.viewCount = viewCount;
	}

	@Transient
	public Integer getIsAttention() {
		return isAttention;
	}

	public void setIsAttention(Integer isAttention) {
		this.isAttention = isAttention;
	}

	@Transient
	public Integer getIsRecommended() {
		return isRecommended;
	}

	public void setIsRecommended(Integer isRecommended) {
		this.isRecommended = isRecommended;
	}

	//@JsonIgnore//去掉时，发起项目报remainingday空指针异常
	@Transient
	public Integer getRemainingDay() {

		return remainingDay;
	}

	public void setRemainingDay(Integer remainingDay) {
		this.remainingDay = remainingDay;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getFundraisingDate() {
		return fundraisingDate;
	}

	public void setFundraisingDate(Date fundraisingDate) {
		this.fundraisingDate = fundraisingDate;
	}
	
	@Transient
	@JsonIgnore
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getEndDate(){
		Date endDate=this.createdDate;
		endDate.setDate(endDate.getDate()+validDays);
		return endDate;
	}

}
